package exam;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.Stack;

/**
 * @author shentianyu
 * @date 2021-07-02 21:12
 */
public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in, StandardCharsets.UTF_8.name());
        String expression = cin.nextLine();
        cin.close();
        String result = calculate(expression);
        System.out.println(result);
    }

    // 待实现函数，在此函数中填入答题代码
    // 1+2*3-100/2
    private static String calculate(String expression) {
        Stack<Integer> numbers = new Stack<>();
        Stack<Character> symbols = new Stack<>();
        int length = expression.length();
        char[] chars = expression.toCharArray();
        int start =0;
        for (int i = 0; i <length ; i++) {
            if(chars[i]=='+'||chars[i]=='-'||chars[i]=='*'||chars[i]=='/'){
                String stringNum = expression.substring(start, i);
                start=i+1;
                Integer valueNum = Integer.valueOf(stringNum);
                //获取到一个数字后，首先要看它前面的符号是什么
                //如果是乘号或除号，那么就要把前面的数字拿过来进行运算
                //如果是加号或者减号，那么要继续判断它后面的符号
                if(!symbols.isEmpty()){
                    char lastSymbol = symbols.peek();
                    if(lastSymbol=='*'){
                        symbols.pop();
                        Integer lastValue = numbers.pop();
                        Integer newValue = lastValue.intValue()*valueNum.intValue();
                        numbers.push(newValue);
                        symbols.push(chars[i]);
                    } else if (lastSymbol=='/'){
                        if(valueNum==0){
                            return "error";
                        }
                        symbols.pop();
                        Integer lastValue = numbers.pop();
                        Integer newValue = lastValue.intValue()/valueNum.intValue();
                        numbers.push(newValue);
                        symbols.push(chars[i]);
                    } else {
                        //如果前面的符号是加号或者减号，要对后面的符号进行继续判断
                        //如果后面是乘号或者除号，那么直接放进栈中
                        //如果后面是加号或者减号，那么看情况进行操作
                        char nextSymbol = chars[i];
                        if(nextSymbol=='*'||nextSymbol=='/'){
                            numbers.push(valueNum);
                            symbols.push(nextSymbol);
                        } else {
                            if(lastSymbol=='+'){
                                symbols.pop();
                                Integer lastValue = numbers.pop();
                                Integer newValue = lastValue.intValue()+valueNum.intValue();
                                numbers.push(newValue);
                                symbols.push(chars[i]);
                            } else {
                                symbols.pop();
                                Integer lastValue = numbers.pop();
                                Integer newValue = lastValue.intValue()-valueNum.intValue();
                                numbers.push(newValue);
                                symbols.push(chars[i]);
                            }
                        }
                    }
                } else {
                    numbers.push(valueNum);
                    symbols.push(chars[i]);
                }
            }
        }
        int lastNum = Integer.valueOf(expression.substring(start)).intValue();

        while(!symbols.isEmpty()){
            char symbol = symbols.pop();
            Integer num = numbers.pop();
            if(symbol=='+'){
                lastNum = num+lastNum;
            }else if(symbol=='-'){
                lastNum = num-lastNum;
            }else if (symbol=='*'){
                lastNum = num*lastNum;
            } else {
                if(lastNum==0){
                    return "error";
                }
                lastNum = num/lastNum;
            }
        }
        return String.valueOf(lastNum);
    }
}
